package org.nowcoder.huawei.other;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeMap;

/**
 * HJ8: 合并表记录
 */
public class HJ8 {
    public static void HJ8(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        TreeMap<Integer, Integer> map = new TreeMap<>();

        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            String[] val = br.readLine().split(" ");
            int k = Integer.parseInt(val[0]);
            int v = Integer.parseInt(val[1]);
            if (map.get(k) == null) {
                map.put(k, v);
            } else {
                map.put(k, v + map.get(k));
            }
        }

        for (Integer i : map.keySet()) {
            System.out.println(i + " " + map.get(i));
        }
    }
}
